package cc.stonemarket.caricature.action;

import android.app.Application;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import cc.stonemarket.caricature.biz.DBManager;
import cc.stonemarket.caricature.model.Book;
import cc.stonemarket.caricature.server.IWebDataSource;

/**应用程序的全局变量容器*/
public class GlobalVar extends Application {

	public boolean debugEnabled;
	/**应用程序配置操作对象*/
	SharedPreferences config;
	/**处理与服务器数据交换的对象*/
	IWebDataSource dataServer;
	/**处理数据库操作的对象*/
	DBManager dbManager;
	/**处理图片问题的对象*/
//	ImageManager imageManager;

	Book selectedBook;
	int lastMainListPosition;

	// ArrayList<Book> bookCacheList;
	// TODO use onRetainNonConfigurationInstance for quick config state/cache
	// for longer term cache use state bean relative to Activity referenced via
	// application
//	BookSearchStateBean bookSearchStateBean;

	public void onCreate() {
		super.onCreate();
		config = PreferenceManager.getDefaultSharedPreferences(this);
//		dbManager = new DBManager(this);
//		imageManager = new ImageManager(this);
		connectServer();
	}

	/**建立网络数据来源*/
	void connectServer() {
		//dataServer=
	}

	// so that onSaveInstanceState/onRestoreInstanceState can use with just saved id
	public void establishSelectedBook(final long id) {
//		selectedBook = dataManager.selectBook(id);
	}

	/**退出应用时，清空内存*/
	public void onTerminate() {
		// not guaranteed to be called
//		dataManager.closeDb();
//		selectedBook = null;
		super.onTerminate();
	}
}











